package stocks.client.gui.controller.actions;

import stocks.client.gui.model.model;

import java.awt.event.ActionEvent;
import java.rmi.RemoteException;
import java.util.ArrayList;

import javax.swing.AbstractAction;
import javax.swing.JTable;

public class ViewAction extends AbstractAction{

	private model m;
	
	/**
	 * Constructor, takes model as a parameter
	 */
	public ViewAction(model m)
	{
		this.m = m;
	}
	@Override
	public void actionPerformed(ActionEvent e) {
		
		ArrayList<String> al = new ArrayList<String>();
		
		try {
			al = m.getRMIInterface().getStockPrices(m);
		} catch (RemoteException ex) {
			// TODO Auto-generated catch block
			ex.printStackTrace();
		}
		JTable results = m.getViewFrame().getStockTable();
		int i = 0;
		int row = 0;
		while(al.size() > i)
		{
			results.setValueAt(al.get(i), row, 1);
			row++;
			i++;
		}
		m.getViewFrame().setVisible(true); //show view frame
		
	}

}
